# -*- coding: UTF-8 -*-
from django.contrib import admin
from django.utils.translation import gettext_lazy as _
from .models import BenefitType, Position, Job, Employee, UserPlainPassword


@admin.register(BenefitType)
class BenefitTypeAdmin(admin.ModelAdmin):
    list_display = ['name', 'display_name', 'code', 'category', 'appear_on_payslip', 'active', 'order', 'amount_fix', 'amount_percentage']
    list_display_links = ['name']
    search_fields = ['name', 'code', 'display_name']
    list_filter = ['category', 'active', 'appear_on_payslip']
    
    fieldsets = (
        (_('基本信息'), {
            'fields': ('name', 'display_name', 'code', 'category', 'active', 'order')
        }),
        (_('薪资设置'), {
            'fields': ('appear_on_payslip', 'amount_fix', 'amount_percentage', 'amount_code')
        }),
        (_('其他信息'), {
            'fields': ('placeholder', 'note')
        }),
    )


@admin.register(Position)
class PositionAdmin(admin.ModelAdmin):
    list_display = ['name', 'importance', 'private_description', 'public_description']
    list_display_links = ['name']
    search_fields = ['name', 'private_description', 'public_description']
    list_filter = ['importance']
    
    fieldsets = (
        (_('基本信息'), {
            'fields': ('name', 'importance')
        }),
        (_('描述信息'), {
            'fields': ('private_description', 'public_description')
        }),
    )


@admin.register(Job)
class JobAdmin(admin.ModelAdmin):
    list_display = ['status', 'published_status', 'pay', 'benefits', 'department', 'position', 'location', 'num_of_planed_employees', 'num_of_vacancies']
    list_display_links = ['status']
    search_fields = ['department', 'position', 'location']
    list_filter = ['status', 'published_status', 'department', 'position']
    
    fieldsets = (
        (_('基本信息'), {
            'fields': ('status', 'published_status', 'department', 'position', 'location')
        }),
        (_('薪资福利'), {
            'fields': ('pay', 'benefits')
        }),
        (_('招聘信息'), {
            'fields': ('num_of_planed_employees', 'num_of_vacancies', 'slug')
        }),
        (_('其他信息'), {
            'fields': ('note',)
        }),
    )


@admin.register(Employee)
class EmployeeAdmin(admin.ModelAdmin):
    list_display = ['name', 'user', 'description', 'gender', 'internal_id', 'department', 'job', 'join_date']
    list_display_links = ['name']
    search_fields = ['name', 'internal_id', 'description']
    list_filter = ['gender', 'department', 'job', 'join_date']
    date_hierarchy = 'join_date'
    
    fieldsets = (
        (_('基本信息'), {
            'fields': ('name', 'user', 'description', 'gender', 'internal_id')
        }),
        (_('工作信息'), {
            'fields': ('department', 'job', 'join_date')
        }),
        (_('其他信息'), {
            'fields': ('note',)
        }),
    )


@admin.register(UserPlainPassword)
class UserPlainPasswordAdmin(admin.ModelAdmin):
    list_display = ['username', 'password']
    list_display_links = ['username']
    search_fields = ['username']
    
    fieldsets = (
        (_('登录信息'), {
            'fields': ('username', 'password')
        }),
    )
